package com.freeter;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.tio.server.TioServer;
import org.voovan.network.aio.AioServerSocket;

import cn.hutool.setting.dialect.Props;

/**
 * SpringBoot启动之后执行
 *
 * @author zhangtao
 * @version 1.0
 * @since 2018/7/4
 */
@Component
@Order(1)
public class ServerRunner implements CommandLineRunner {
	@Autowired
    private  TioServer tioServer;
	@Autowired
    private  AioServerSocket voovanServer;
    private static final Logger logger = LoggerFactory.getLogger(ServerRunner.class);

    @Override
    public void run(String... args) throws IOException {
        logger.info("ServerRunner 开始启动啦...");
        Props props = new Props("socket_config.properties");
        String socketWrap = props.getProperty("socketWrap");
        String serverIp = props.getProperty("serverIp");
        int serverPort = props.getInt("serverPort");
    	if("t-io".equals(socketWrap)){
    		logger.info("使用网络通信框架t-io 开始启动...");
    		tioServer.start(serverIp, serverPort);
    	}else if("voovan".equals(socketWrap)){
    		voovanServer.start();
    		logger.info("使用网络通信框架voovan 开始启动...");
    	}else if("netty".equals(socketWrap)){
    		logger.info("使用网络通信框架netty 开始启动...");
    	}
       
    }
}
